package com.fivefu.core.skyeye.event.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
//import com.fivefu.core.module.auth.utils.SecurityUtil;
import com.fivefu.core.skyeye.event.services.DbAiSceneTypeService;
import com.fivefu.core.skyeye.event.utils.VerifyDataUtils;
import com.fivefu.core.skyeye.event.vo.SceneTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

@Api(tags = "识别类型")
@RestController
@RequestMapping("/scene_type")
public class DbAiSceneTypeController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(DbAiSceneTypeController.class);

    @Autowired
    private DbAiSceneTypeService dbAiSceneTypeService;

    @RequestMapping(path = "/querySceneTypeList",method = RequestMethod.POST)
    @ApiOperation(value = "分页获取识别类型列表",httpMethod = "POST",response = ResultInfo.class,notes = "分页获取识别类型列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query",required = true, dataType = "int"),
            @ApiImplicitParam(name = "limit", value = "数量", paramType = "query",required = true, dataType = "int")
    })
    public ResultInfo querySceneTypeList(Integer page, Integer limit){
        try {
            logger.info("分页获取识别类型列表接收参数：" + JSON.toJSONString(request.getParameterMap()));
            if (page == null){
                return   ResultInfo.renderError("页码不能为空");
            }
            //判断每页显示条数是否为空
            if (limit == null){
                return   ResultInfo.renderError("数量不能为空");
            }
            Page<Map<String, Object>> list = dbAiSceneTypeService.querySceneTypeList(page, limit);
            return ResultInfo.renderSuccess(list);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return ResultInfo.renderError("分页获取识别类型列表失败");
    }

    @RequestMapping(path = "/querySceneTypeDetail",method = RequestMethod.POST)
    @ApiOperation(value = "获取识别类型详情",httpMethod = "POST",response = ResultInfo.class,notes = "获取识别类型详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "识别类型编号", paramType = "query",required = true, dataType = "Long"),
    })
    public ResultInfo querySceneTypeDetail(Long id){
        try {
            logger.info("获取识别类型详情接收参数：" + JSON.toJSONString(request.getParameterMap()));
            if (id == null){
                return   ResultInfo.renderError("识别类型编号不能为空");
            }
            Map<String, Object> sceneType = dbAiSceneTypeService.querySceneTypeDetail(id);
            return ResultInfo.renderSuccess(sceneType);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return ResultInfo.renderError("获取识别类型详情失败");
    }

    @RequestMapping(path = "/editSceneType",method = RequestMethod.POST)
    @ApiOperation(value = "编辑识别类型",httpMethod = "POST",response = ResultInfo.class,notes = "编辑识别类型")
    public ResultInfo editSceneType(@ModelAttribute @Valid SceneTypeVo sceneTypeVo, @RequestAttribute String userid){
        try {
            logger.info("编辑识别类型接收数据：" + JSON.toJSONString(request.getParameterMap()));
            String value = VerifyDataUtils.verifyRequiredColumn(sceneTypeVo);
            if (StrUtils.isNotNull(value)){
                return ResultInfo.renderError(value + "不能为空");
            }
            dbAiSceneTypeService.editSceneType(sceneTypeVo, userid);
            return ResultInfo.renderSuccess("编辑识别类型成功");
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return ResultInfo.renderError("编辑识别类型失败");
    }

}
